package com.r2coding.server.common.utils;

import com.r2coding.core.constants.Constants;

import java.util.Objects;

/**
 * @author 98k灬
 * @version v1.0.0
 * @Description : 用户ID存储工具类
 * @Create on : 2023/10/8 12:59
 **/
public class UserIdUtil {
    private static ThreadLocal<Long> threadLocal = new ThreadLocal<>();

    public static void set(Long userId) {
        threadLocal.set(userId);
    }

    public static Long get() {
        Long userId = threadLocal.get();
        if (Objects.isNull(userId)) {
            return Constants.ZERO_LONG;
        }
        return userId;
    }
}
